#include "widget.h"
#include "ui_widget.h"

#include <QIcon>
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
//    QIcon icon(":/dog.jpg");
//    ui->pushButton->setIcon(icon);
//    ui->pushButton->setIconSize(QSize(50, 50));
    // 设置图标
    ui->pushButton_target->setIcon(QIcon(":/dog.jpg"));
    ui->pushButton_target->setIconSize(QSize(150, 150));

    ui->pushButton_up->setIcon((QIcon(":/up.png")));
    ui->pushButton_down->setIcon((QIcon(":/down.png")));
    ui->pushButton_left->setIcon((QIcon(":/left.png")));
    ui->pushButton_right->setIcon((QIcon(":/right.png")));

    // 设置大小
    ui->pushButton_up->setIconSize(QSize(30, 30));
    ui->pushButton_down->setIconSize(QSize(30, 30));
    ui->pushButton_left->setIconSize(QSize(30, 30));
    ui->pushButton_right->setIconSize(QSize(30, 30));

    // 设置快捷键
    ui->pushButton_up->setShortcut(QKeySequence("w"));
    ui->pushButton_down->setShortcut(QKeySequence("s"));
    ui->pushButton_left->setShortcut(QKeySequence("a"));
    ui->pushButton_right->setShortcut(QKeySequence("d"));

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_up_clicked()
{
    const QRect& rect = ui->pushButton_target->geometry();
    ui->pushButton_target->setGeometry(rect.x(), rect.y() - 5, rect.width(), rect.height());
    qDebug() << "up";
}

void Widget::on_pushButton_down_clicked()
{
    const QRect& rect = ui->pushButton_target->geometry();
    ui->pushButton_target->setGeometry(rect.x(), rect.y() + 5, rect.width(), rect.height());
    qDebug() << "down";
}

void Widget::on_pushButton_left_clicked()
{
    const QRect& rect = ui->pushButton_target->geometry();
    ui->pushButton_target->setGeometry(rect.x() - 5, rect.y(), rect.width(), rect.height());
    qDebug() << "left";
}

void Widget::on_pushButton_right_clicked()
{
    const QRect& rect = ui->pushButton_target->geometry();
    ui->pushButton_target->setGeometry(rect.x() + 5, rect.y(), rect.width(), rect.height());
    qDebug() << "right";
}

